<template>
    <view>
        <view class="cu-card dynamic" v-for="(comment, index) in commentData" :key="index">
            <view class="cu-item shadow">
                <view class="cu-list menu-avatar">
                    <view class="cu-item">
                        <view class="cu-avatar round lg" :style="'background-image:url(' + comment.AvatarUrl + ');'"></view>
                        <view class="content flex-sub">
                            <view>{{ comment.name }}</view>
                            <view class="text-gray text-sm flex justify-between">
                                {{ comment.time }}
                            </view>
                        </view>
                    </view>
                </view>
                <view class="text-content">
                    <!-- <template is="wxParse" :data="wxParseData:ContentArr[index]"/> -->
                    <mp-html :content="comment.content"></mp-html>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
// pages/bbs/bbs.js

const app = getApp();

const getData = (url, param) => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: url,
            method: 'POST',
            data: param,
            header: {
                'Content-Type': 'application/json'
            },

            success(res) {
                resolve(res.data);
            },

            fail(err) {
                reject(err);
            }
        });
    });
};

export default {
    data() {
        return {
            commentData: [],
            userInfo: {},
            webConfig: {},
            SafeCode: uni.getStorageSync('SafeCode'),

            comment: {
                AvatarUrl: '',
                name: '',
                time: ''
            },

            ContentArr: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        this.onLoadClone3389(options);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.onLoadClone3389({});
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        /**
         * 生命周期函数--监听页面加载
         */
        onLoadClone3389: function (options) {
            uni.showLoading({
                title: '加载中...'
            });
            var that = this;
            getData(app.globalData.ApiUrl + 'api/Android/webConfig', {}).then((msg) => {
                that.setData({
                    webConfig: msg
                });
            });
            getData(app.globalData.ApiUrl + 'api/Android/UserInfo', {
                SafeCode: that.SafeCode
            }).then((msg) => {
                that.setData({
                    userInfo: msg
                });
            });
            getData(app.globalData.ApiUrl + 'api/Android/MyComment', {
                SafeCode: that.SafeCode
            }).then((msg) => {
                that.setData({
                    commentData: msg
                });

                uni.hideLoading();
            });
        }
    }
};
</script>
<style>
@import './bbs.css';
</style>
